package com.sci.controller;

import com.sci.entity.CommonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fallback")
public class FallbackController {

    @RequestMapping
    public CommonResult<String> defaultFallback() {
        return new CommonResult<>(403, "Gateway触发了熔断降级", null);
    }

    @RequestMapping("/user")
    public CommonResult<String> userFallback() {
        return createServiceUnavailableResult("用户服务");
    }

    @RequestMapping("/business")
    public CommonResult<String> businessFallback() {
        return createServiceUnavailableResult("业务服务");
    }

    @RequestMapping("/order")
    public CommonResult<String> orderFallback() {
        return createServiceUnavailableResult("订单服务");
    }

    @RequestMapping("/shipment")
    public CommonResult<String> shipmentFallback() {
        return createServiceUnavailableResult("物流服务");
    }

    @RequestMapping("/food")
    public CommonResult<String> foodFallback() {
        return createServiceUnavailableResult("食品服务");
    }

    @RequestMapping("/unauthorized")
    public CommonResult<String> unauthorized() {
        return new CommonResult<>(401, "未经授权: 缺少有效的鉴权信息", null);
    }

    private CommonResult<String> createServiceUnavailableResult(String serviceName) {
        return new CommonResult<>(503, serviceName + "不可用，请稍后重试", null);
    }
}